<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('学生信息列表')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>学生姓名：</label>
                                <input type="text" name="studentName"/>
                            </li>
                            <li>
                                <label>学号：</label>
                                <input type="text" name="studentNo"/>
                            </li>
                            <li>
                                <label>年级：</label>
                                <select   id='gradeId' name='gradeId' >
                                </select>
                            </li>
                            <li>
                                <label>班级名称：</label>
                                <select   id='classId' name='classId'>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('sc_student_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="school:student:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editFull()" shiro:hasPermission="school:student:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="school:student:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="school:student:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="school:student:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: datetimepicker-js" />
     <th:block th:include="include :: bootstrap-select-js" />
     <!-- 导入区域 -->
     <script id="importTpl" type="text/template">
         <form enctype="multipart/form-data" class="mt20 mb10">
             <div class="col-xs-offset-1">
                 <input type="file" id="file" name="file"/>
                 <div class="mt10 pt5">
                     请按照模板导入学生数据
                     &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
                 </div>
                 <font color="red" class="pull-left mt10">
                     提示：仅允许导入“xls”或“xlsx”格式文件！
                 </font>
             </div>
         </form>
     </script>
    <script th:inline="javascript">
        $(document).ready(function(){

            $.ajax({
                type: "post",
                url:ctx + "school/grade/getGradeList",
                async:false,
                dataType: "json",
                success: function(res){
                    if (null != res) {
                        var html = '<option value="">所有</option>';
                        Object.keys(res).forEach(function(key){
                            html += '<option value="' + res[key].id + '" data-tokens="'+ res[key].gradeName+'">' + res[key].gradeName+ '</option>';
                        });
                        $("#gradeId").html(html);
                        //必须加，刷新select
                        $("#gradeId").selectpicker('refresh');
                    }
                }
            });


            //绑定bootstrap-select事件
            $.ajax({
                type: "post",
                url:ctx + "school/classInfo/getClassList",
                async:false,
                dataType: "json",
                success: function(res){
                    if (null != res) {
                        var html = '<option value="">所有</option>';
                        Object.keys(res).forEach(function(key){
                            html += '<option value="' + res[key].id + '" data-tokens="'+ res[key].className+'">' + res[key].className+ '</option>';
                        });
                        $("#classId").html(html);
                        //必须加，刷新select
                        $("#classId").selectpicker('refresh');
                    }
                }
            });
        });

        var editFlag = [[${@permission.hasPermi('school:badge:edit')}]];
        var removeFlag = [[${@permission.hasPermi('school:badge:remove')}]];
        var statusDatas = [[${@dict.getType('sc_student_status')}]];
        var prefix = ctx + "school/student";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importTemplateUrl: prefix + "/importTemplate",
                importUrl: prefix + "/importData",
                modalName: "学生信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: 'id',
                    visible: false
                },
                {
                    field: 'studentNo',
                    title: '学号'
                },
                {
                    field: 'studentName', 
                    title: '学生姓名'
                },
                {
                    field: 'img',
                    title: '照片',
                    formatter:function (value, row, index) {
                        if($.common.isNotEmpty(value)){
                            return '<img src="'+value+'" class="img-circle img-xs">'
                        }

                    }
                },
                {
                    field: 'gradeName',
                    title: '年级'
                },
                {
                    field: 'className', 
                    title: '班级名称'
                },
                {
                    field: 'status', 
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'balance',
                    title: '账户余额'
                },
                {
                    field: 'parentsMobile', 
                    title: '家长电话'
                },
                {
                    field: 'parentsName', 
                    title: '家长姓名'
                },
                {
                    field: 'address', 
                    title: '住址'
                },
                {
                    field: 'comeDate', 
                    title: '入学时间'
                },
                {
                    field: 'leaveDate', 
                    title: '离校时间'
                },

                {
                    field: 'comeScore',
                    title: '入学分数'
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>